package it.uniroma2.art.coda.structures;

import it.uniroma2.art.coda.pearl.model.PlaceholderStruct;
import it.uniroma2.art.coda.pearl.model.ProjectionRule;
import it.uniroma2.art.owlart.model.ARTNode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * This class contains the final suggestion from CODA: the triple that should be added to the ontology
 * 
 * @author Andrea Turbati
 * 
 */
public class CodaFinalSuggestions extends InterComponentObject {

	// the list of triple the external program should add to the ontology
	List<ARTTriple> artTripleList;
	// a map containng for each projection rules used the placeholder and the associated ARTNode
	Map<ProjectionRule, Map<PlaceholderStruct, List<? extends ARTNode>>> projRuleToPlacehoderToARTNodeMap;

	//Map<ProjectionRule, Boolean> projRuleSucceded;

	public CodaFinalSuggestions() {
		artTripleList = new ArrayList<ARTTriple>();
		projRuleToPlacehoderToARTNodeMap = new HashMap<ProjectionRule, Map<PlaceholderStruct, List<? extends ARTNode>>>();
		//projRuleSucceded = new HashMap<ProjectionRule, Boolean>();
	}

	/**
	 * Add a triple to the list of triple that should be added to the ontology
	 * 
	 * @param artTriple
	 *            the triple that should be added to the ontology
	 * @return true if the triple was not already present int the list, false oherwise
	 */
	public boolean addTriple(ARTTriple artTriple) {
		if (artTripleList.contains(artTriple))
			return false;
		artTripleList.add(artTriple);
		return true;
	}

	/**
	 * Get the list of Triples
	 * 
	 * @return the list of triples
	 */
	public List<ARTTriple> getTriplesList() {
		return artTripleList;
	}

	/**
	 * Add a list of value regarding a placeholder for a particular projection rule
	 * 
	 * @param projRule
	 *            the projection rule to which the placeholder belongs to
	 * @param placeholder
	 *            the placeholder to which the list of values belongs to
	 * @param artNodeList
	 *            the list of values for the palceholder
	 */
	public void addPlaceholderToARTNode(ProjectionRule projRule, PlaceholderStruct placeholder,
			List<? extends ARTNode> artNodeList) {
		if (projRuleToPlacehoderToARTNodeMap.get(projRule) == null)
			projRuleToPlacehoderToARTNodeMap.put(projRule,
					new HashMap<PlaceholderStruct, List<? extends ARTNode>>());
		projRuleToPlacehoderToARTNodeMap.get(projRule).put(placeholder, artNodeList);
	}

	/**
	 * Get the list of values for a particular placeholder
	 * 
	 * @param placeholder
	 *            the placeholder to which the returned list belongs to
	 * @return the list of values associated to the particular placeholder
	 */
	//public List<? extends ARTNode> getARTNodeFromPlaceholder(PlaceholderStruct placeholder) {
	//	ProjectionRule projRule = placeholder.getProjRule();
	//	Map<PlaceholderStruct, List<? extends ARTNode>> projRuleLabelMap = projRuleToPlacehoderToARTNodeMap
	//			.get(projRule);
	//	if (projRuleLabelMap == null)
	//		return null;
	//	return projRuleLabelMap.get(placeholder);
	//}

	/**
	 * Set the success/unsuccess for a particular projection rule
	 * 
	 * @param projRule
	 *            the projection rule that succeeded or unsucceeded
	 * @param succeded
	 *            true if the projection rule succeeded, false otherwise
	 */
	//public void addProjRuleSucceed(ProjectionRule projRule, boolean succeded) {
	//	projRuleSucceded.put(projRule, new Boolean(succeded));
	//}

	/**
	 * Get the success/unsuccess for a particular projection rule
	 * 
	 * @param projRule
	 *            the projection rule we want to check
	 * @return true if the projection rule succeeded, false otherwise
	 */
	//public Boolean getSuccededFromProjRule(ProjectionRule projRule) {
	//	return projRuleSucceded.get(projRule).booleanValue();
	//}
}
